import Vue from 'vue'
import Router from 'vue-router'
import Login from '@/components/Login'
import Home from '@/components/Home/';
import { getCookie } from '@/assets/utils'

//代理管理
const ProxyManage = resolve => require(['@/components/Home/ProxyManage/'], resolve);
//权利金管理
const RightsGoldManage = resolve => require(['@/components/Home/RightsGoldManage/'], resolve);

//点差管理
const SpreadManage = resolve => require(['@/components/Home/SpreadManage/'], resolve);

//订单管理
const OrdersManageProxy = resolve => require(['@/components/Home/OrdersManage/order_proxy'], resolve);

const OrdersManageMaster= resolve => require(['@/components/Home/OrdersManage/'], resolve);

//行权申请管理
const ExerciseApplyManage = resolve => require(['@/components/Home/ExerciseApplyManage/'], resolve);

//财务管理
const FinanceManage = resolve => require(['@/components/Home/FinanceManage/'], resolve);

//报表管理
const ReportManage = resolve => require(['@/components/Home/ReportManage/'], resolve);

//询价
const SearchPriceManage = resolve => require(['@/components/Home/SearchPriceManage/'], resolve);




//角色管理
const RolesManage = resolve => require(['@/components/Home/OrganizationManage/RolesManage'], resolve);
//用户管理
const UsersManage = resolve => require(['@/components/Home/OrganizationManage/UsersManage'], resolve);


Vue.use(Router)

let router = new Router({
    routes: [{
        path: '/',
        name: 'login',
        component: Login
    }, {
        path: '/home',
        name: 'home',
        component: Home,
        children: [ //组织结构管理
            {
                path: 'menu_proxy_manage',
                name: 'menu_proxy_manage',
                component: ProxyManage,
                props:{breadcrumb:{name:'代理管理',parent:''}}
            },
            {
                path: 'menu_rights_go_manage',
                name: 'menu_rights_go_manage',
                component: RightsGoldManage,
                props:{breadcrumb:{name:'权利金管理',parent:''}}
            },
            {
                path: 'menu_spread_manage',
                name: 'menu_spread_manage',
                component: SpreadManage,
                props:{breadcrumb:{name:'点差管理',parent:''}}
            },
            {
                path: 'menu_order_manage_proxy',
                name: 'menu_order_manage_proxy',
                component: OrdersManageProxy,
                props:{breadcrumb:{name:'代理订单管理',parent:''}}
            },
            {
                path: 'menu_order_manage_master',
                name: 'menu_order_manage_master',
                component: OrdersManageMaster,
                props:{breadcrumb:{name:'Master订单管理',parent:''}}
            },
            {
                path: 'menu_apply_manage',
                name: 'menu_apply_manage',
                component: ExerciseApplyManage,
                props:{breadcrumb:{name:'行权申请管理',parent:''}}
            },
            {
                path: 'menu_finance_manage',
                name: 'menu_finance_manage',
                component: FinanceManage,
                props:{breadcrumb:{name:'财务管理',parent:''}}
            },
            {
                path: 'menu_report_manage',
                name: 'menu_report_manage',
                component: ReportManage,
                props:{breadcrumb:{name:'报表管理',parent:''}}
            },
            {
                path: 'menu_search_price',
                name: 'menu_search_price',
                component: SearchPriceManage,
                props:{breadcrumb:{name:'询价&交易',parent:''}}
            },
            {
                path: 'menu_zzjg_roles',
                name: 'menu_zzjg_roles',
                component: RolesManage,
                props:{breadcrumb:{name:'角色管理',parent:'组织机构管理'}}
            },
            {
                path: 'menu_zzjg_users',
                name: 'menu_zzjg_users',
                component: UsersManage,
                props:{breadcrumb:{name:'用户管理',parent:'组织机构管理'}}
            },
        ]
    }, ]
})

// 路由跳转前验证
// router.beforeEach((to, from, next) => {
//     if (to.matched.length === 0) { //如果未匹配到路由
//         next({ name: 'error' }); //如果上级也未匹配到路由则跳转登录页面，如果上级能匹配到则转上级路由
//     } else {
//         if (getCookie('navName') !== undefined) {
//             store.dispatch('setNavName', getCookie('navName'));
//         }
//         next();
//     }
// });
export default router;